/**
 * COPY TASKs
 * @Author: jiangcheng198745@hotmail.com
 * @Date: 2016/07/30 
 */
'use strict';

import gulp from 'gulp';
import runSeq  from 'run-sequence';
import {reload} from 'browser-sync';
import {argv as args} from 'yargs';

import messageLogger from '../utils/message.gulp';
import config from '../gulp.config';

gulp.task('copy:build',  (done) => {
    messageLogger('Copying build files');
    runSeq([
        'copy:build-app-files',
        'copy:build-vendor-css',
        'copy:build-vender-fonts',
        'copy:build-vender-images',
        'copy:build-vender-js'
    ],
    done);
});

gulp.task('copy:build-app-files', () => {
    var files =[].concat(
        config.app + '/*.{ico,png,ttf,txt,html}',
        '!' + config.app + '/index.html',
        config.app + '/' + config.images + '/**/*',
        config.app + '/' + config.font + '/**/*',
        config.appFiles.js,
        config.appFiles.jsx,
        config.appFiles.json,
        config.app + '/.htaccess',
        '!' + config.testFiles.spec.all
    );
    messageLogger('Copying application files', files)

    return gulp.src(files, {
        base: config.app
    })
    .pipe(gulp.dest(config.build))
    .pipe(reload({
        stream: true
    }));
});


gulp.task('copy:build-vendor-css', () => {

    messageLogger('Copying vendor JS files', config.vendorFiles.js);
    return gulp.src(config.vendorFiles.css, {
            base: './'
        })
        .pipe(gulp.dest(config.build));
})

gulp.task('copy:build-vender-fonts', () => {

})

gulp.task('copy:build-vender-images', () => {

})


gulp.task('copy:build-vender-js', () => {
    messageLogger('Copying vendor JS files', config.vendorFiles.js);
    return gulp.src(config.vendorFiles.js, {
        base: './'
    })
    .pipe(gulp.dest(config.build));
})



gulp.task('copy:dist', (done) => {
    runSeq([
        'copy:dist-app-files'/**,
        'copy:dist-vender-fonts'*/
    ]);
});

gulp.task('copy:dist-app-files', () => {
    var files = [].concat(
        '**/*.svg',
        '**/*.ttf',
        '*.{txt,html}',
        '**/*.json',
        '.htaccess'
    );
    messageLogger('Copying application files', files);
    return gulp.src(files, {
        cwd: config.build,
        base: config.build
    })
    .pipe(gulp.dest(config.dist));
});
